﻿#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

//int main()
//{
//	std::vector<int> v{ 1,4,3,2,5 };
//	sort(v.begin(), v.end(),std::greater<int>());
//
//	for (auto e : v)
//	{
//		std::cout << e << ' ';
//	}
//	std::cout << std::endl;
//
//	return 0;
//}


struct Goods
{
	string _name;
	double _price;
	int _evaluate; 
	Goods(const char* str, double price, int evaluate)
	:_name(str),_price(price),_evaluate(evaluate)
	{}
};

int main()
{
	vector<Goods> v = { { "苹果", 2.1, 5 }, { "香蕉", 3, 4 }, { "橙子", 2.2,
	3 }, { "菠萝", 1.5, 4 } };
	sort(v.begin(), v.end(), [](const Goods& g1, const Goods& g2) {
		return g1._price < g2._price; });
	for (auto e : v)
	{
		cout << e._price << ' ';
	}
	cout << endl;

	sort(v.begin(), v.end(), [](const Goods& g1, const Goods& g2) {
		return g1._price > g2._price; });
	for (auto e : v)
	{
		cout << e._price << ' ';
	}
	cout << endl;

	sort(v.begin(), v.end(), [](const Goods& g1, const Goods& g2) {
		return g1._evaluate < g2._evaluate; });
	for (auto e : v)
	{
		cout << e._evaluate << ' ';
	}
	cout << endl;

	sort(v.begin(), v.end(), [](const Goods& g1, const Goods& g2) {
		return g1._evaluate > g2._evaluate; });
	for (auto e : v)
	{
		cout << e._evaluate << ' ';
	}
	cout << endl;
}